<template>
  <div class="main">
    <el-button type="primary" class="btnAdd" @click="handAdd">新增</el-button>
    <el-table border :data="tableData" style="width: 100%" fit stripe highlight-current-row lazy>
      <el-table-column width="50" label="序号" type="index"></el-table-column>
      <el-table-column prop="versionScrore" label="版本总分"></el-table-column>
      <el-table-column prop="versionState" label="版本状态"></el-table-column>
      <el-table-column prop="address" label="描述"></el-table-column>
      <el-table-column prop="jjj" label="版本发布时间"></el-table-column>
      <el-table-column prop="kkk" label="创建人"></el-table-column>
      <el-table-column prop="address" label="操作">
        <el-link type="primary" size="mini" plain @click="handEdit">编辑</el-link>
        <el-link type="primary" size="mini" plain @click="detect">删除</el-link>
        <el-link type="primary" size="mini" plain @click="handledetail">维度配置</el-link>
      </el-table-column>
    </el-table>
    <!-- <dialogEngin v-if="dialogVisible" :dialogVisible="dialogVisible" @close="close"></dialogEngin> -->
    <el-dialog :title="title" :visible.sync="showDate" width="700px" :before-close="dialogClose">
      <el-form
        ref="formData"
        :model="formData"
        :rules="rules"
        label-position="left"
        label-width="110px"
        size="mini"
      >
        <el-form-item label="版本总分" prop="versionScrore">
          <el-input v-model="formData.versionScrore"></el-input>
        </el-form-item>
        <el-form-item label="版本状态" prop="versionState">
          <el-select v-model="formData.versionState" placeholder="请选择">
            <el-option label="启用" value="0"></el-option>
            <el-option label="禁用" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="版本发布时间" prop="jjj">
          <el-date-picker
            v-model="formData.jjj"
            type="date"
            placeholder="选择日期"
            :clearable="true"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="描述" prop="address">
          <el-input v-model="formData.address"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="showDate=false">关闭</el-button>
        <el-button type="primary" size="mini" @click="menuSave()">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import dialogEngin from "./dialogEngin";
export default {
  name: "version.vue",
  // components: { dialogEngin },
  data() {
    return {
      dialogVisible: false,
      showDate: false,
      title: "新增",
      tableData: [
        {
          versionScrore: "1",
          versionState: "禁用",
          address: "1",
          jjj: "2021-11-02",
          kkk: "k70563",
        },
        {
          versionScrore: "100",
          versionState: "启用",
          address: "2",
          jjj: "2021-10-22",
          kkk: "k40563",
        },
        {
          versionScrore: "33",
          versionState: "禁用",
          address: "版本测试",
          jjj: "2021-12-23",
          kkk: "23411",
        },
        {
          versionScrore: "66",
          versionState: "启用",
          address: "4",
          jjj: "2021-12-25",
          kkk: "542113",
        },
      ],
      formData: {
        versionScrore: "",
        versionState: "",
        jjj: "",
        address: "",
      },
      rules: {
        versionScrore: [
          { required: true, message: "版本总分名称必填", trigger: "blur" },
        ],
        versionState: [
          { required: true, message: "版本状态必填", trigger: "blur" },
        ],
        jjj: [{ required: true, message: "日期必填", trigger: "blur" }],
      },
    };
  },
  methods: {
    //新增
    handAdd() {
      this.title = "新增";
      this.showDate = true;
    },
    //编辑
    handEdit(row) {
      this.title = "修改";
      Object.keys(this.formData).forEach((key) => {
        this.formData[key] = row[key];
      });
      // this.formData.versionScrore = obj.versionScrore;
      // this.formData.versionState = obj.versionState;
      // this.formData.jjj = obj.jjj;
      // this.formData.address = obj.address;
      
      this.showDate = true;
    },
    //保存
    menuSave() {
      this.$refs["formData"].validate((valid) => {
        if (valid) {
          if (this.title == "新增") {
            this.formData.versionScrore = "";
            query(this.formData).then(() => {
              if (res && res.code == 200) {
                this.showDate = false;
                var msg = "添加成功";
                this.$message({
                  message: msg,
                  type: "success",
                });
                for (let key in this.formData) {
                  this.formData[key] = "";
                }
              } else {
                this.$message.warning(res.message);
              }
            });
          } else {
            query(this.formData).then(() => {
              if (res && res.code == 200) {
                this.showDate = false;
                var msg = "修改成功";
                this.$message({
                  message: msg,
                  type: "success",
                });
                for (let key in this.formData) {
                  this.formData[key] = "";
                }
              } else {
                this.$message.warning(res.message);
              }
            });
          }
        }
      });
    },
    detect(row) {
      this.$confirm("删除该行", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        var ids = [];
        ids.push(row.funcId);
        // delect({ids:ids}).then(()=>{
        //     this.fetchData(this.listQuery)
        //     this.rowClickSelection=null
        //     this.$message({
        //         message:"删除成功",
        //         type:"成功"
        //     })
        // })
      });
    },
    dialogClose() {
      this.showDate = false;
      for (let key in this.formData) {
        this.formData[key] = "";
      }
    },
    handledetail(e, index) {
      this.$emit("nextProp", e, "craft");
    },
  },
};
</script>

<style lang="scss" scoped>
.main {
  margin-top: 50px;
  position: relative;
  .btnAdd {
    position: absolute;
    right: 20px;
    top: -45px;
  }
  .el-link {
    margin-left: 10px;
  }
}
</style>
